import {defineStore} from "pinia";
import type {TrademarkItemType} from "@/api/trademark";
import {reqGetTrademarkListAsync} from "@/api/trademark";

//定义当前store的state类型
export interface tmStoreStateType {
    trademarkList: TrademarkItemType[];
    pages: number;
}

const useTrademarkStore = defineStore("trademark", {
    state: (): tmStoreStateType => {
        return {
            //品牌列表
            trademarkList: [],
            //品牌列表的总页数
            pages: 0,
        }
    },
    actions: {
        //1. 获取品牌的分页列表
        async getTrademarkList(page: number, limit: number) {
            try {
                const result = await reqGetTrademarkListAsync(page, limit);
                //拿到品牌详情之后，把数据分别交给state来管理
                this.trademarkList = result.records;
                this.pages = result.pages;
            } catch (e) {
                return Promise.reject(e);
            }
        },
    }
})

export default useTrademarkStore